module Fighter {
	/**
 * 跟随僚机---周泽东
 *  
 * */
	export class FollowFly {
		constructor(tshowPanel) {
			this.showPanle = tshowPanel;

		}
	
		/**显示的容器*/
		public showPanle: any;
		/**玩家位置 */
		public playerPos: egret.Point;

		/**左跟随型僚机 */
		public lFollowPlane: egret.Bitmap;
		/**右跟随型僚机 */
		public rFollowPlane: egret.Bitmap;
		/**玩家飞机 */
		public player: egret.Bitmap;
		/**发射子弹 */
		public fire: egret.Timer;
		/**初始化 */
		public init(player:egret.Bitmap) {



			if (this.lFollowPlane == null) {
				this.lFollowPlane = new egret.Bitmap();
				this.lFollowPlane.texture = RES.getRes("liaoji1_png");
				this.lFollowPlane.x = player.x-30;
				this.lFollowPlane.y =player.y;
			}
			if (this.rFollowPlane == null) {
				this.rFollowPlane = new egret.Bitmap();
				this.rFollowPlane.texture = RES.getRes("liaoji1_png");
				this.rFollowPlane.x = player.x+30;
				this.rFollowPlane.y =player.y;
			}
			if (this.fire == null) {
				this.fire = new egret.Timer(150, 0);
				this.fire.addEventListener(egret.TimerEvent.TIMER, this.createBullet, this);
				
			}
			this.fire.start();
			this.showPanle.addChild(this.lFollowPlane);
			this.showPanle.addChild(this.rFollowPlane);


		}
		/**跟随方法 */
		public follow() {
			this.playerPos = GameUtil.PlayerMessage.instance.player_position;
			this.lFollowPlane.x = this.playerPos.x - 80;
			this.lFollowPlane.y = this.playerPos.y + 100;
			this.rFollowPlane.x = this.playerPos.x + 80;
			this.rFollowPlane.y = this.playerPos.y + 100;

		}

		public removeSelf() {
			if (this.lFollowPlane.parent) {
				this.lFollowPlane.parent.removeChild(this.lFollowPlane);
			}
			if (this.rFollowPlane.parent) {
				this.rFollowPlane.parent.removeChild(this.rFollowPlane);
			}
			this.fire.reset();
			
		}
		/**飞机创建子弹*/
		public createBullet() {
			let point = new egret.Point(this.lFollowPlane.x + this.lFollowPlane.width / 2, this.lFollowPlane.y);
			let point_ = new egret.Point(this.rFollowPlane.x + this.rFollowPlane.width / 2, this.rFollowPlane.y);
			this.showPanle.BulletManager.createBullet(0, point)
			this.showPanle.BulletManager.createBullet(0, point_)
		}

	}
}